package com.ql.service.sbglService.impl;

import com.ql.dao.sheBeiGuanLi.wxMapper;
import com.ql.pojo.sheBeiGuanLi.WeiXiu;
import com.ql.service.sbglService.wxService;
import com.ql.utils.PageHelper;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
@Service("wxservice")
public class wxServiceImpl implements wxService {
    private static final Logger logger=Logger.getLogger(wxServiceImpl.class);
    @Resource
    private wxMapper wxMapper;
    //获取维修所有信息
    @Override
    public List<WeiXiu> getAllWx(PageHelper ph,String mohuName) {
        List<WeiXiu> weiXiuList=new ArrayList<WeiXiu>();
        try {
            //add:更新总条数
            ph.setTotalCount(wxMapper.qryCount(mohuName));
            weiXiuList=wxMapper.qryAll((ph.getCurrentPageNo()-1)*ph.getPageSize(),ph.getPageSize(),mohuName);
            if(weiXiuList.size()<=0){
                logger.debug("wxServiceImpl.getAllWx查询为空！");
            }else {
                logger.error("wxServiceImpl.getAllWx查询成功！");
            }
        } catch (Exception e) {
//            e.printStackTrace();
            logger.error("wxServiceImpl.getAllWx查询异常！"+e.getMessage());
        }
        return weiXiuList;
    }
    //单个删除
    @Override
    public boolean removeWX(int wId) {
        int row=0;
        try {
            row=wxMapper.del(wId);
            if(row !=1){
                logger.debug("wxServiceImpl.removeWX 删除维修失败!");
                return false;
            }else{
                logger.debug("wxServiceImpl.removeWX 删除维修成功!");
                return true;
            }
        } catch (Exception e) {
//            e.printStackTrace();
            logger.error("wxServiceImpl.removeWX 删除维修异常!"+e.getMessage());
            return false;
        }
    }
    //批量删除
    @Override
    public boolean deleteBatch(List<Integer> list) {
        try {
            int row=wxMapper.delBatch(list);
            if(row !=0){
                logger.debug("wxServiceImpl.deleteBatch 删除维修成功!");
                return true;
            }else {
                logger.debug("wxServiceImpl.deleteBatch 删除维修失败!");
                return false;
            }
        } catch (Exception e) {
//            e.printStackTrace();
            logger.error("wxServiceImpl.deleteBatch 删除维修异常!");
            return false;
        }
    }
    //获取id查看详情信息
    @Override
    public WeiXiu getWXById(String wId) {
        WeiXiu weiXiu=null;
        try {
            weiXiu=wxMapper.qryById(wId);
        } catch (Exception e) {
//            e.printStackTrace();
            logger.error("wxServiceImpl.getWXById查询详情异常！"+e.getMessage());
            weiXiu=new WeiXiu();
        }
        return weiXiu;
    }
    //新增维修信息
    @Override
    public boolean addNewWX(WeiXiu weiXiu) {
        int row=0;
        try {
            row=wxMapper.save(weiXiu);
            if(row !=1){
                logger.debug("wxServiceImpl.addNewWX 新增维修失败！");
                return false;
            }else{
                logger.debug("wxServiceImpl.addNewWX 新增维修成功！");
                return true;
            }
        } catch (Exception e) {
//            e.printStackTrace();
            logger.error("wxServiceImpl.addNewWX 新增维修异常！"+e.getMessage());
            return false;
        }
    }
    //修改维修信息
    @Override
    public boolean updateWX(WeiXiu weiXiu) {
        boolean updateWX=false;
        try {
            int row=wxMapper.modify(weiXiu);
            if(row==1){
                logger.debug("wxServiceImpl.updateWX修改维修成功！");
                updateWX=true;
            }else {
                logger.debug("wxServiceImpl.updateWX修改维修失败！");
                updateWX=false;
            }
        } catch (Exception e) {
//            e.printStackTrace();
            logger.error("wxServiceImpl.updateWX修改维修异常！"+e.getMessage());
            updateWX=false;
        }
        return updateWX;
    }
}
